package com.syh.jn.scm.infrastructure.repository.impl.downstream.finance;

import cn.redscarf.commons.wrapper.Wrapper;
import com.syh.core.ddd.infrastructure.repository.AbstractAggregateRepository;
import com.syh.jn.scm.domain.downstream.entity.finance.DownBusinessAccountRecord;
import com.syh.jn.scm.domain.downstream.repository.finance.DownBusinessAccountRecordRepository;
import com.syh.jn.scm.dto.downstream.finance.DownBusinessAccountRecordVo;
import com.syh.jn.scm.infrastructure.repository.model.finance.BusinessAccountRecordModel;
import com.syh.jn.scm.infrastructure.repository.utils.SQLAliasGenerateUtil;
import com.syh.jn.scm.infrastructure.wrapper.BaseResolve;
import com.syh.jn.scm.infrastructure.wrapper.ResolveToSQL;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * 应收付记录Repository实现
 */
@Repository
public class DownBusinessAccountRecordRepositoryImpl extends AbstractAggregateRepository<DownBusinessAccountRecord, BusinessAccountRecordModel, Long> implements DownBusinessAccountRecordRepository {
  @Override
  protected SQL getViewSql() {

    return new SQL(){{
      SELECT(
              SQLAliasGenerateUtil.aliasGenerate(BusinessAccountRecordModel.class,"downRecord", null)
      );
      FROM("T_FINANCE_BUSINESS_ACCOUNT_RECORD AS downRecord");
    }};
  }

  @Override
  protected BaseResolve getViewWrapperResolve(Wrapper wrapper) {
    Map<String,String> map = new HashMap<>();
    map.put("id","downRecord.ID");
    map.put("originalDocumentCode","downRecord.ORIGINAL_DOCUMENT_CODE");
    map.put("originalDocumentType","downRecord.ORIGINAL_DOCUMENT_TYPE");
    map.put("customerId","downRecord.CUSTOMER_ID");
    map.put("customerType","downRecord.CUSTOMER_TYPE");
    map.put("createTimeStamp","downRecord.CREATE_TIME_STAMP");
    map.put("businessEntityId", "downRecord.BUSINESS_ENTITY_ID");

    ResolveToSQL parse = new ResolveToSQL(wrapper, (propertyName) -> {
      return map.get(propertyName);
    });
    return parse;
  }

  @Override
  protected Class getViewObject() {
    return DownBusinessAccountRecordVo.class;
  }
}
